﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Move_User_AttView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string pronum = Session["pro_num"].ToString();
        //string userid = Request.QueryString["id"];
        string proname = "";
        string danwei = "";
        string place = "";
        string auditor = "";
        string condition = "";
        string category = "";
        string buydate = "";
        string ordernot = "";
        string manuname = "";
        string manuinfo = "";
        string worth = "";
        string operation = "";
        string function = "";
        string remarks = "";
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        string path = "";
        //string function = "";
        string repair = "";
        string attribute = "";
        try
        {
            conn.Open();
            string SQLimg = "select pro_img from Products where pro_num=@pronum";
            SqlCommand cmdimg = new SqlCommand();
            cmdimg.Connection = conn;
            cmdimg.CommandType = CommandType.Text;
            cmdimg.CommandText = SQLimg;
            SqlParameter p1 = new SqlParameter("@pronum", pronum);
            cmdimg.Parameters.Add(p1);
            //cmdimg.ExecuteNonQuery();
            path = cmdimg.ExecuteScalar().ToString();

            //显示仪器个别属性
            string SQLatt = "select keyword,pro_value from Attribute where att_num=@pronum";
            SqlCommand cmdatt = new SqlCommand();
            cmdatt.Connection = conn;
            cmdatt.CommandType = CommandType.Text;
            cmdatt.CommandText = SQLatt;
            SqlParameter p2 = new SqlParameter("@pronum", pronum);
            cmdatt.Parameters.Add(p2);        
            using (SqlDataReader readeratt = cmdatt.ExecuteReader())
            {
                while (readeratt.Read())
                {   //  reader [0]  为序数列的值，  “XH” 学号字段的值
                    attribute += readeratt["keyword"] + "&nbsp;";
                    attribute += readeratt["pro_value"] + "<br />";
                }
            }

            //显示设备详细信息
            string SQLmeg = "select pro_num,pro_name,pro_danwei,pro_location,auditor,condition,pro_category,buydate,ordernot,pro_manuname,pro_manuinfo,pro_worth,operation_manual,pro_function,remarks from Products where (pro_num=@pro_num and flag=1)";
            SqlCommand cmdmeg = new SqlCommand();
            cmdmeg.Connection = conn;
            cmdmeg.CommandText = SQLmeg;
            cmdmeg.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter pusername = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            pusername.Value = pronum;
            cmdmeg.Parameters.Add(pusername);
            //如果还有其他参数，一并添加
            //使用 SqlDataReader循环读取数据
            using (SqlDataReader reader = cmdmeg.ExecuteReader())
            {
                while (reader.Read())      //如果可以读（有数据），就开始读
                {
                    pronum = reader["pro_num"].ToString();
                    proname = reader["pro_name"].ToString();
                    danwei = reader["pro_danwei"].ToString();
                    place = reader["pro_location"].ToString();
                    auditor = reader["auditor"].ToString();
                    condition = reader["condition"].ToString();
                    category = reader["pro_category"].ToString();
                    buydate = reader["buydate"].ToString();
                    ordernot = reader["ordernot"].ToString();
                    manuname = reader["pro_manuname"].ToString();
                    manuinfo = reader["pro_manuinfo"].ToString();
                    worth = reader["pro_worth"].ToString();
                    operation = reader["operation_manual"].ToString();
                    function = reader["pro_function"].ToString();
                    remarks = reader["remarks"].ToString();
                }
                Labela1.Text = pronum;
                Labela2.Text = proname;
                Labela3.Text = danwei;
                Labela4.Text = place;
                Labela5.Text = auditor;
                Labela6.Text = condition;

                Labela7.Text = category;
                Labela8.Text = buydate;
                Labela9.Text = ordernot;
                Labela10.Text = manuname;
                HyperLink1.NavigateUrl = "Operation/" + operation;
                Labela12.Text = worth;

                HyperLink2.Text = manuinfo;
                HyperLink2.NavigateUrl = manuinfo;
                Labela14.Text = function;
                Labela15.Text = remarks;
            }
            //显示仪器功能
            //string SQLfunc = "select pro_function from Products where pro_num=@pronum";
            //SqlCommand cmdfunc = new SqlCommand();
            //cmdfunc.Connection = conn;
            //cmdfunc.CommandType = CommandType.Text;
            //cmdfunc.CommandText = SQLfunc;
            //SqlParameter p3 = new SqlParameter("@pronum", pronum);
            //cmdfunc.Parameters.Add(p3);
            //function = cmdfunc.ExecuteScalar().ToString();
            //仪器维修记录
            //string SQLrep = "select date_inform,rep_cause,date_rep,rep_program from Repair where pro_num=@pronum";
            //SqlCommand cmdrep = new SqlCommand();
            //cmdrep.Connection = conn;
            //cmdrep.CommandType = CommandType.Text;
            //cmdrep.CommandText = SQLrep;
            //SqlParameter p4 = new SqlParameter("@pronum", pronum);
            //cmdrep.Parameters.Add(p4);
            //using (SqlDataReader readerrep = cmdrep.ExecuteReader())
            //{
            //    while (readerrep.Read())
            //    {   //  reader [0]  为序数列的值，  “XH” 学号字段的值
            //        repair += "<b>报修时间：</b>";
            //        repair += readerrep["date_inform"] + "&nbsp;";
            //        repair += "<b>报修原因：</b>";
            //        repair += readerrep["rep_cause"] + "<br />";

            //        string flag = readerrep["date_rep"].ToString();
            //        if (flag != "")
            //        {
            //            repair += "<b>维修时间：</b>";
            //            repair += readerrep["date_rep"] + "&nbsp;";
            //            repair += "<b>维修时间：</b>";
            //            repair += readerrep["rep_program"] + "<br />";
            //        }
            //    }
            //}


            //其他属性显示
            string tabelall = "<table class='layui-table'><thead> <tr><td colspan='8' style='background-color: #EEE;font-size:large;text-align:center'>该设备的其他属性</td></tr><tr><th>属性名称</th><th>属性值</th></tr></thead>";
            SqlCommand cmdmsg = new SqlCommand();
            string SQLmsg = "select keyword,pro_value from Attribute where att_num=@pro_num";
            cmdmsg.Connection = conn;
            cmdmsg.CommandText = SQLmsg;
            cmdmsg.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter ppro_num = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            ppro_num.Value = pronum;
            cmdmsg.Parameters.Add(ppro_num);
            int k = 0;
            using (SqlDataReader readermsg = cmdmsg.ExecuteReader())
            {
                int fieldcount = readermsg.FieldCount;      //取字段总数
                if (!readermsg.HasRows)            //有数据  ---行
                {
                    MsgKey.Text = "<table class='layui-table' style='width: 70%; margin-left:15% '><tr><td>此仪器没有被添加过其他属性</td></tr>";
                }
                else
                {
                    string trd = "<tbody>";                     //存储数据
                    while (readermsg.Read())               //当有数据可读时
                    {
                        trd += "<tr>";         //数据行开始，行以tr起
                        for (int i = 0; i < fieldcount; i++)
                        {   //每一列的内容
                            trd += "<td>" + readermsg[i].ToString() + "</td>";
                        }
                       /* trd += "<td><a title='删除' onclick='member_del_details(this,readermsg[0].ToString())' href='javascript:;'><i class='layui-icon'>&#xe640;</i></td></tr>";  */           //行结束
                        k = k + 1;
                    }
                    //trd += "<tr><td colspan = '4'><button class='layui-btn layui-btn-danger' onclick='delAll()'><i class='layui-icon'></i>批量删除</button></td></tr>";
                    MsgKey.Text = tabelall + trd + "</tbody></table>";
                }
            }

            //维修记录
            //string tabelrep = "<table class='layui-table'><thead> <tr><td colspan='8' style='background-color: #EEE;font-size:large;text-align:center'>该设备的报修维修记录</td></tr><tr><th>报修时间</th><th>报修原因</th><th>维修时间</th><th>维修过程</th></tr></thead>";
            //string SQLrep = "select date_inform,rep_cause,date_rep,rep_program from Repair where (pro_num=@pronum and flag=1)";
            //SqlCommand cmdrep = new SqlCommand();
            //cmdrep.Connection = conn;
            //cmdrep.CommandType = CommandType.Text;
            //cmdrep.CommandText = SQLrep;
            //SqlParameter p4 = new SqlParameter("@pronum", pronum);
            //cmdrep.Parameters.Add(p4);
            //using (SqlDataReader readerrep = cmdrep.ExecuteReader())
            //{                  
            //    int fieldcount = readerrep.FieldCount;      //取字段总数
            //    if (!readerrep.HasRows)            //有数据  ---行
            //    {
            //        LabelRepair.Text = "<table class='layui-table' style='width: 70%; margin-left:15% '><tr><td>此仪器没有报修维修记录</td></tr>";
            //    }
            //    else
            //    {
            //        string trd = "<tbody>";                     //存储数据
            //        while (readerrep.Read())               //当有数据可读时
            //        {
            //            trd += "<tr>";         //数据行开始，行以tr起
            //            for (int i = 0; i < fieldcount; i++)
            //            {   //每一列的内容
            //                trd += "<td>" + readerrep[i].ToString() + "</td>";
            //            }
            //                //行结束
            //        }

            //        LabelRepair.Text = tabelrep + trd + "</tbody></table>";
            //    }
            //}

        }
        finally
        {
            conn.Close();
        }
        ImgPhoto.ImageUrl = "/Photos/" + path;
        //LabFunction.Text = function;
        //LabRepair.Text = repair;
        //LabAtt.Text = attribute;
    }
}